﻿using Microsoft.AspNetCore.Mvc.Filters;

namespace CommonUtils
{
    public class FilterOfResource : IResourceFilter
    {
        public void OnResourceExecuting(ResourceExecutingContext context)
        {
            (ReflectionUtil.GetSenderClassName() + "." + ReflectionUtil.GetSenderMethodName()
                + " start FilterOfResource: "
                 + context.HttpContext.Request.Path).Print();
        }

        public void OnResourceExecuted(ResourceExecutedContext context)
        {
            (ReflectionUtil.GetSenderClassName() + "." + ReflectionUtil.GetSenderMethodName()
                + " end FilterOfResource: "
          + context.HttpContext.Request.Path).Print();
        }

        public static void AddTo(IServiceCollection services)
        {
            services.AddMvc(options => options.Filters.Add<FilterOfResource>());
        }
    }
}
